home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 147_01 / utlx.c < prev    next >
Text File  |  1985-03-09  |  8KB  |  317 lines

  1. /****************************************************************
  2. * UTLX.C        Variant of UTIL.C to convert files    *
  3.  
  4. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  5.  
  6. * Functions included in this file are:
  7.  
  8. * main        calls chk_user, subject, select_subj, and performs
  9.         the main command loop
  10.  
  11. * chk_user    checks to see if USERS.CCC exists, and calls nu_user
  12.         to create it if it doesn't.
  13.  
  14. * rite_user    (Case 2) creates USER.$$$, selectively copies each
  15.         user, one at a time from USER.CCC. Then renames
  16.         USER.CCC to USER.BAK and USER.$$$ to USER.BAK
  17.  
  18. * subject    checks to see if SUBJECTS.CCC exists, and calls
  19.         creat_subj if not.  Then calls displ_subj to
  20.         display the available subjects.
  21.  
  22. * readsum    special conversion version from RBBSFN.C
  23.  
  24. ****************************************************************/
  25.  
  26. #include    <bdscio.h>
  27. #include    "rbbs4.h"
  28.  
  29. main()
  30. {
  31.     char    c[2];
  32.     int    i;
  33.     int    fd, ufd;
  34.     struct    _sum    s;
  35.     struct    _user    u;
  36.  
  37. #if    DATETIME
  38.     get_date();
  39.     strcpy(logdate,sysdate);
  40. #endif
  41.     upstr("dummy");
  42.     setptr(m,lp);
  43.     chk_user();
  44. #if    !PERSONLY
  45.     subject();
  46. #else
  47.     strcpy(cmsgfile,"PERSONAL");
  48.     sprintf(msgfile,"%s%s%s",DRIVE,capstr(cmsgfile),".MSG");
  49.     msgct = load_cntrl(0,s);
  50.     msg_info(msgct,TRUE);
  51. #endif
  52.     while(TRUE)
  53.     {
  54. outstr("**************************************************************",2);
  55. outstr("<1> Convert USERS.CCC file from 4.0 to 4.1 format",2);
  56. outstr("<2> Convert a Subject file from 4.0 to 4.1 format",1);
  57.         outstr("<9> Quit",2);
  58.         crlf(1);
  59.         outstr("Enter choice: ",4);
  60.         instr("",c,1);
  61.         crlf(1);
  62.         switch(*c-0x30)
  63.         {
  64.             case 1:
  65.                 rite_user(u);
  66.                 break;
  67.  
  68.             case 2:
  69. #if    !PERSONLY
  70.                 select_subj(0,s);
  71.                 msgct = load_cntrl(0,s);
  72.                 msg_info(msgct,FALSE);
  73. #endif
  74.                 rite_active(msgct,s);
  75.                 outstr("Loading new control",2);
  76.                 msgct = nload_cntrl(msgct,s);
  77.                 msg_info(msgct,TRUE);
  78.                 for ( i = 1; i <= msgct; i++)
  79.                     prnt_ndx(i);
  80.                 break;
  81.  
  82.             case 9:
  83.                 outstr("Finished",2);
  84.                 exit();
  85.                 break;
  86.  
  87.             default:
  88.                 outstr("Choice Error",2);
  89.                 break;
  90.         }
  91.     }
  92. }
  93. /****************************************************************/
  94. chk_user()
  95. {
  96.     int    fd;
  97.     int    bias;
  98.     char    input[10];
  99.  
  100.     crlf(1);
  101.     if ( (fd = open(DSK(USERS.CCC),2)) == ERROR)
  102.         ioerr("USERS.CCC does not exist");
  103.     else
  104.         close(fd);    
  105. }
  106. /****************************************************************/
  107. rite_user(u)            /* Conversion version        */
  108. struct    _user    *u;
  109. {
  110.     int    i,j,k;
  111.     int    fdin,fdout;
  112.     int    inct,outct;
  113.     char    nm1[11];
  114.     char    nm2[11];
  115.     
  116.     outct = 1;
  117.     if ( (fdin = open(DSK(USERS.CCC),2)) == ERROR)
  118.         ioerr("Cannot open USERS.CCC");
  119. #if    LOCKEM
  120.     if (lokrec(fdin,-1))
  121.         ioerr("locking USERS.CCC");
  122. #endif
  123.     if ((fdout= creat(DSK(USERS.$$$)))== ERROR)
  124.         ioerr("Creating USERS.$$$ file");
  125.     if ( seek(fdout,1,0) == ERROR)
  126.         ioerr("Seek in USERS.$$$");
  127.     readrec(fdin,0,tmpstr,1);
  128.     sscanf(tmpstr,"MAX REC: %d",&inct);
  129.     for ( i = 1; i <= inct; i++)
  130.     {
  131.         formrec(tmpstr,SECSIZ);
  132.         readrec(fdin,i,tmpstr,1);
  133.         sscanf(tmpstr+0,"%s",nm2);        /* NM2:    */
  134.         if (*nm2)
  135.         {
  136.             sscanf(tmpstr+16,"%s",nm1);    /* NM1:    */
  137.             sprintf(u->nm,"%s %s",nm1,nm2);
  138.         }
  139.         else
  140.             sscanf(tmpstr+16,"%s",u->nm);
  141.         sscanf(tmpstr+32,"%s",u->ustat);    /* PRV:    */
  142.         sscanf(tmpstr+34,"%s",u->pwd);        /* PWD:    */
  143.         sscanf(tmpstr+41,"%s",u->lastlog);    /* LLG:    */
  144.         sscanf(tmpstr+65,"%d",&u->lstmsg[0]);    /* LMG:    */
  145.         sscanf(tmpstr+70,"%d",&u->bellflag);    /* UBL:    */
  146.         sscanf(tmpstr+75,"%d",&u->xpert);    /* UXP:    */
  147.         sscanf(tmpstr+95,"%s",u->from);        /* FRM:    */
  148.         printuser(u);
  149.         crlf(1);
  150.         if (getyn("Write rec"))
  151.         {
  152.             formrec(tmpstr,SECSIZ);
  153.             sprintf(tmpstr+NM,"%s",u->nm);        /* NM:    */
  154.             sprintf(tmpstr+PRV,"%s",u->ustat);    /* PRV:    */
  155.             sprintf(tmpstr+UBL,"%1d",u->bellflag);    /* UBL:    */
  156.             sprintf(tmpstr+UXP,"%1d",u->xpert);    /* UXP:    */
  157.             sprintf(tmpstr+PWD,"%s",u->pwd);    /* PWD:    */
  158.             sprintf(tmpstr+LLG,"%s",u->lastlog);    /* LLG:    */
  159.             sprintf(tmpstr+FRM,"%s",u->from);    /* FRM:    */
  160.             sprintf(tmpstr+LMG0,"%03d",u->lstmsg[0]);
  161.             sprintf(tmpstr+LMG1,"%03d",0);
  162.             sprintf(tmpstr+LMG2,"%03d",0);
  163.             sprintf(tmpstr+LMG3,"%03d",0);
  164.             sprintf(tmpstr+LMG4,"%03d",0);
  165.             sprintf(tmpstr+LMG5,"%03d",0);
  166.             sprintf(tmpstr+LMG6,"%03d",0);
  167.             Rriterec(fdout,outct++,1,tmpstr);
  168.         }
  169.     }
  170.     formrec(tmpstr,SECSIZ);
  171.     sprintf(tmpstr,"MAX REC: %d",--outct);
  172.     Rriterec(fdout,0,1,tmpstr);
  173.     if ( close(fdout) == ERROR)
  174.         ioerr("Closing USERS.$$$");
  175.  
  176. #if    LOCKEM
  177.     frerec(fdin,-1);
  178. #endif
  179.     if ( close(fdin) == ERROR)
  180.         ioerr("Closing USERS.CCC");
  181.     unlink(DSK(USERS.BAK));
  182.     if ( rename(DSK(USERS.CCC),DSK(USERS.BAK)) == ERROR)
  183.         ioerr("Renaming USERS.CCC to USERS.BAK");
  184.     if ( rename(DSK(USERS.$$$),DSK(USERS.CCC)) == ERROR)
  185.         ioerr("Renaming USERS.$$$ to USERS.CCC");
  186. }
  187. /***************************************************************/    
  188. #if    !PERSONLY
  189. subject()
  190. {
  191.     int    i,fd,n;
  192.  
  193.     crlf(1);
  194.     if ( (fd = open(DSK(SUBJECTS.CCC),2)) == ERROR)
  195.         ioerr("SUBJECTS.CCC does not exist");
  196.     if ( readrec(fd,0,tmpstr,1) == ERROR)
  197.         ioerr("reading the subject record");
  198.     sscanf(tmpstr,"%d",&n);
  199.     displ_subj(fd,n,tmpstr);
  200.     close(fd);    
  201. }
  202. #endif
  203. /****************************************************************/
  204. readsum(fd,recno,s)
  205. int    fd,recno;
  206. struct    _sum    *s;
  207. {
  208.     int    blks;
  209.     char    nm1[11];
  210.     char    nm2[11];
  211.  
  212.     if ( readrec(fd,recno,tmpstr,1) == ERROR)
  213.         return(ERROR);
  214.  
  215.     /* SSCANF CONSTANT INFORMATION */
  216.     sscanf(tmpstr,"%d ",&s->msgno);        /* MSG:    */
  217.     sscanf(tmpstr+10,"%d ",&s->lct);    /* LNS:    */
  218.     sscanf(tmpstr+18,"%d ",&s->mstat);    /* STAT:*/
  219.     sscanf(tmpstr+26,"%s",s->date);        /* DT:    */
  220.     sscanf(tmpstr+61,"%s",nm2);
  221.     if (*nm2)
  222.     {
  223.         sscanf(tmpstr+51,"%s",nm1);    /* FM:    */
  224.         sprintf(s->fnm,"%s %s",nm1,nm2);
  225.     }
  226.     else
  227.         sscanf(tmpstr+51,"%s",s->fnm);
  228.     sscanf(tmpstr+82,"%s",nm2);
  229.     if (*nm2)
  230.     {
  231.         sscanf(tmpstr+72,"%s",nm1);    /* TO:    */
  232.         sprintf(s->tnm,"%s %s",nm1,nm2);
  233.     }
  234.     else
  235.         sscanf(tmpstr+72,"%s",s->tnm);
  236.     sscanf(tmpstr+93,"%s",s->subj);        /* SU:    */
  237.     blks = (s->lct+3)/2;
  238.     return(recno+blks);
  239. }
  240. /***************************************************************/    
  241. nload_cntrl(msgct,s)
  242. int    msgct;
  243. struct    _sum    *s;
  244. {
  245.     int    msgfd;
  246.  
  247.     if ( (msgfd = open(msgfile,2)) == ERROR)
  248.     {
  249.         sprintf(tmpstr,"Creating %s",msgfile);
  250.         outstr(tmpstr,1);
  251.         if ( (msgfd = creat(msgfile)) == ERROR)
  252.             ioerr("Creating msgfile");
  253.         mno[1] = mndx[1] = 0;
  254.         if (close(msgfd) == ERROR)
  255.             ioerr("Closing Msg");
  256.         return 0;
  257.     }
  258.     msgct = nloadsum(msgfd,s);
  259.     if (close(msgfd) == ERROR)
  260.         ioerr("Closing Msg");
  261.     return msgct;
  262. }
  263. /***************************************************************/
  264. nloadsum(fd,s)
  265. int    fd;
  266. struct    _sum    *s;
  267. {
  268.     int    ct, i, siz;
  269.  
  270.     ct = siz = 0;
  271.     for ( i = 1; i< MAXMSGS; i++)
  272.     {
  273.         if ( (ct = nreadsum(fd,ct,s)) == ERROR)
  274.         {
  275.             mndx[i] = mndx[i-1] + siz;
  276.             mno[i] = 0;
  277.             return (i-1);
  278.         }
  279.         if (i)
  280.             mndx[i] = mndx[i-1] + siz;
  281.         else
  282.             mndx[0] = 0;
  283.         siz = (s->lct+3)/2;
  284.         if (s->mstat)
  285.             mno[i] = s->msgno;
  286.         else
  287.             mno[i] = 0;
  288.     }
  289. }
  290. /***************************************************************/
  291. nreadsum(fd,recno,s)
  292. int    fd,recno;
  293. struct    _sum    *s;
  294. {
  295.     int    blks;
  296.  
  297.     if ( readrec(fd,recno,tmpstr,1) == ERROR)
  298.         return(ERROR);
  299.  
  300.     /* SSCANF CONSTANT INFORMATION */
  301.     sscanf(tmpstr,"%d ",&s->msgno);        /* MSG:    */
  302.     sscanf(tmpstr+LNS,"%d ",&s->lct);    /* LNS:    */
  303.     sscanf(tmpstr+STAT,"%d ",&s->mstat);    /* STAT:*/
  304.     sscanf(tmpstr+DT,"%s",s->date);        /* DT:    */
  305.     sscanf(tmpstr+FM,"%s",s->fnm);        /* FM:    */
  306.     sscanf(tmpstr+TO,"%s",s->tnm);        /* TO:    */
  307.     sscanf(tmpstr+SU,"%s",s->subj);        /* SU:    */
  308.     blks = (s->lct+3)/2;
  309.     return(recno+blks);
  310. }
  311. /****************************************************************/
  312. nt    ct, i, siz;
  313.  
  314.     ct = siz = 0;
  315.     for ( i = 1; i< MAXMSGS; i++)
  316.     {
  317.         if ( (ct = nreadsum(fd,ct,s)) == E